import math
import numpy as np
def calculate_distance(x1, x2, y1, y2, z1, z2, scaled_x, scaled_y):
    """ 计算两个点之间的欧几里得距离 """
    return math.sqrt(((x1 - x2)/scaled_x) ** 2 + ((y1 - y2)/scaled_y) ** 2 + ((z1 - z2) ** 2))
def cal_rectangle(hand_landmarks):
        # 计算边界框的最小和最大坐标
        min_x = min([x for x in hand_landmarks[0]])
        min_y = min([y for y in hand_landmarks[1]])
        max_x = max([x for x in hand_landmarks[0]])
        max_y = max([y for y in hand_landmarks[1]])
        return min_x, min_y, max_x, max_y
def get_all_distances(hand_landmarks):
    """计算边界"""
    min_x, min_y, max_x, max_y = cal_rectangle(hand_landmarks)
    scaled_x = abs(max_x - min_x)
    scaled_y = abs(max_y - min_y)
    """ 计算 face_landmarks 中所有点两两之间的距离 """
    num_landmarks = len(hand_landmarks)
    distances = []
    for i in range(num_landmarks):
        for j in range(i + 1, num_landmarks):
            distance = calculate_distance(hand_landmarks[i][0], hand_landmarks[j][0], hand_landmarks[i][1], 
            hand_landmarks[j][1], hand_landmarks[i][2], hand_landmarks[j][2], scaled_x, scaled_y)
            distances.append(distance)
    return np.array(distances)